/**
 * FileOut is a program that outputs simple text to a text file chosen by the user.
 * @author: Alex Fick
 * @version: 1.0.0
 */
import java.io.*;
import javax.swing.JFileChooser;
public class FileOut
{
		FileWriter writer;
		BufferedWriter buf;
		PrintWriter out;
		String filename = "";
	/**
	* Instantiates a FileOut if no filename is sent.
	* Prompts user for a file with a file chooser window.
	**/
	public FileOut()
	{
	   JFileChooser chooser = new JFileChooser();
	   if(chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
	   {
		   File selectedFile = chooser.getSelectedFile();
		   try
		   {
			   writer = new FileWriter(selectedFile);
			   buf = new BufferedWriter(writer);
			   out = new PrintWriter(buf, true);
		   }
		   catch(IOException e)
		   {

			   System.out.println("Your filename is not correct.");
			   System.out.println("Your filename must be an existing text file.");
			   System.out.println("Please, try again.");
			   System.out.println("Enter a new filename:");
		   }
	   }
	}
	/**
	* Instantiates a FileOut if the filename is given.
	* @param filename the path of the file to be written to
	**/
	public FileOut(String filename)
	{
	   try
	   {
		   writer = new FileWriter(filename);
		   buf = new BufferedWriter(writer);
		   out = new PrintWriter(buf, true);
	   }
	   catch(IOException e)
	   {
		   System.out.println("Your filename is not correct.");
		   System.out.println("Your filename must be an existing text file.");
		   System.out.println("Please, try again.");
		   System.out.println("Enter a new filename:");
	   }
	}
	/**
	* Calls the toString() method of a given Object, and prints that string to the given text file.
	* @param in Object to be outputted to text
	*/
	public void println(Object in)
	{
		out.println(in);
	}
	/**
	* Prints an int value to the given text file.
	* @param num the int value to be written
	*/
	public void println(int num)
	{
	   out.println(num);
	}
	/**
	* Prints a double value to the given text file.
	* @param num the double value to be written
	*/
	public void println(double num)
	{
	   out.println(num);
	}
	/**
	* Prints a float value to the given text file.
	* @param num the float value to be written
	*/
	public void println(float num)
	{
	   out.println(num);
	}
	/**
	* Prints a boolean value to the given text file.
	* @param in the boolean value to be written
	*/
	public void println(boolean in)
	{
	   out.println(in);
	}
	/**
	* Prints a long value to the given text file.
	* @param num the long value to be written
	*/
	public void println(long num)
	{
	   out.println(num);
	}
	/**
	* Prints a short value to the given text file.
	* @param num the short value to be written
	*/
	public void println(short num)
	{
	   out.println(num);
	}

	public void print(Object in)
	{
	out.print(in);
	}
	/**
	* Prints an int value to the given text file.
	* @param num the int value to be written
	*/
	public void print(int num)
	{
	out.print(num);
	}
	/**
	* Prints a double value to the given text file.
	* @param num the double value to be written
	*/
	public void print(double num)
	{
	out.print(num);
	}
	/**
	* Prints a float value to the given text file.
	* @param num the float value to be written
	*/
	public void print(float num)
	{
	out.print(num);
	}
	/**
	* Prints a boolean value to the given text file.
	* @param in the boolean value to be written
	*/
	public void print(boolean in)
	{
	out.print(in);
	}
	/**
	* Prints a long value to the given text file.
	* @param num the long value to be written
	*/
	public void print(long num)
	{
	out.print(num);
	}
	/**
	* Prints a short value to the given text file.
	* @param num the short value to be written
	*/
	public void print(short num)
	{
	out.print(num);
	}
}